package org.domain.sigerec.session;

import java.util.Arrays;
import java.util.List;

import org.domain.sigerec.entity.Cliente;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;

@Name("clienteList")
public class ClienteList extends EntityQuery<Cliente> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String[] RESTRICTIONS = { "lower(cliente.nome) like concat(lower(#{clienteList.cliente.nome}),'%')", };

	private Cliente cliente = new Cliente();

	@Override
	public String getEjbql() {
		return "select cliente from Cliente cliente";
	}

	@Override
	public Integer getMaxResults() {
		return 25;
	}

	public Cliente getCliente() {
		return cliente;
	}

	@Override
	public List<String> getRestrictions() {
		return Arrays.asList(RESTRICTIONS);
	}

	private boolean pesquisou;

	public List<Cliente> getClientes() {
		if (pesquisou || getFirstResult()!=null) {
			return getResultList();
		}
		return null;
	}

	public String pesquisar() {
		pesquisou = true;
		return null;
	}
}
